package com.cby.android.sample.adapter

import androidx.recyclerview.widget.DefaultItemAnimator
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.cby.android.sample.R
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import java.util.*

/**
 * @description: RollMoreAdapter
 *
 * @author ChenBaoyang
 * @date 4/23/21 11:07
 */
class RollMoreAdapter : BaseQuickAdapter<String, BaseViewHolder>(R.layout.roll_item_more) {

    override fun convert(holder: BaseViewHolder, item: String) {

        holder.setText(R.id.tv_title_more, item)

        val gridLayoutManager = GridLayoutManager(context, 3)
        val recyclerView = holder.getView<RecyclerView>(R.id.recycler_view_item)
        recyclerView.layoutManager = gridLayoutManager
        recyclerView.itemAnimator = DefaultItemAnimator()

        val datasItem = ArrayList<String>()
        var position = getItemPosition(item)
        if (position == 0) {
            //便民服务
            datasItem.add("垃圾分类")
            datasItem.add("新华字典")
            datasItem.add("二维码生成")
            datasItem.add("扫一扫")
            datasItem.add("扫码记录")
        } else if (position == 1) {
            //生活阅读
            datasItem.add("历史上的今天")
            datasItem.add("笑话段子")
        } else if (position == 2) {
            //休闲旅游
            datasItem.add("周公解梦")
            datasItem.add("婚姻匹配")
            datasItem.add("八字算命")
            datasItem.add("老黄历")
        } else if (position == 3) {
            //工具集合
            datasItem.add("手机号码归属地")
            datasItem.add("IP地址")
            datasItem.add("世界电话区号")
        }

        val itemAdapter = RollMoreItemAdapter()
        recyclerView.adapter = itemAdapter
        itemAdapter.setNewData(datasItem)
    }
}